package algorithmTopics.array;


import java.util.Arrays;

/**
 * 试验6
 *
 * @author 86155
 * @date 2025/04/09
 *
 * 注意test包下的代码都是，解题思路
 * 题目在leetcode上面的，初级算法，依次进行
 */
public class test6 {
    public static void main(String[] args) {
        test6 test6 = new test6();
        Arrays.stream(test6
                .intersect(new int[]{4,7,9,7,6,7},new int[]{5,0,0,6,1,6,2,2,4}))
                .forEach(System.out::println);

    }

    public int[] intersect(int[] nums1, int[] nums2) {

        int[] ans = new int[Math.min(nums1.length, nums2.length)];
        int count = 0;
        for (int i = 0; i < nums2.length; i++) {
            for (int j = 0; j < nums1.length; j++) {
                if (nums2[i] == nums1[j]) {
                    nums1[j] = -1;
                    ans[count] = nums2[i];
                    count++;
                    break;
                }
            }
        }

        int[] back = new int[count];
        System.arraycopy(ans,0,back,0,count);
        return back;
    }

}
